package coder.nav.enums;

import coder.nav.model.vo.NavKeyValueVO;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 消费标识
 */
@Getter
@AllArgsConstructor
public enum NavCashFlagEnums {

    SUB(0, "💰", "支出"),
    ADD(1, "💵", "收入"),
    ;
    private final Integer key;
    private final String icon;
    private final String value;

    public static List<NavKeyValueVO<Integer, String>> getList() {
        List<NavKeyValueVO<Integer, String>> list = new ArrayList<>();
        NavCashFlagEnums[] es = NavCashFlagEnums.values();
        for(NavCashFlagEnums e : es) {
            NavKeyValueVO<Integer, String> vo = new NavKeyValueVO<>();
            vo.setKey(e.getKey());
            vo.setValue(e.getIcon() + " " + e.getValue());
            list.add(vo);
        }
        return list;
    }

    public static NavCashFlagEnums getByKey(Integer key) {
        NavCashFlagEnums[] es = NavCashFlagEnums.values();
        for(NavCashFlagEnums e : es) {
            if(Objects.equals(e.getKey(), key)) {
                return e;
            }
        }
        return null;
    }

    public static String getValueByKey(Integer key) {
        NavCashFlagEnums e = getByKey(key);
        return Objects.nonNull(e) ? e.getValue() : "";
    }

}
